package cn.service.marketingService.MarketingServiceImpl;

import cn.service.marketingService.FlashSaleActivityService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import entity.marketingEntity.FlashSaleActivity;
import entity.marketingEntity.FlashSaleActivityCondition;
import entity.Result;
import mapper.marketingMapper.FlashSaleActivityMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author 朱颢阳
 * @description
 * @time 2024/8/31 10:03
 */
@Service
public class FlashSaleActivityServiceImpl implements FlashSaleActivityService {
    @Resource
    FlashSaleActivityMapper mapper;

    @Override
    public Result getflashsaleactivity(FlashSaleActivityCondition condition) {
        PageHelper.startPage(condition.getCurrentPage(),condition.getPageSize());
        Page<FlashSaleActivity> page= (Page<FlashSaleActivity>) mapper.getflashsaleactivity(condition);
        return Result.success((int)page.getTotal(),page.getResult());
    }

    @Override
    public Result addflashsaleactivity(FlashSaleActivity flashSaleActivity) {
        if (mapper.insertSelective(flashSaleActivity)>0){
            return Result.success("添加成功");
        }else{
            return Result.failed(500,"添加失败");
        }
    }

    @Override
    public Result updateflashsaleactivityOnline(Integer id, Integer online) {
        if (mapper.updateflashsaleactivityOnline(id,online)>0){
            return Result.success("上线状态更新成功");
        }else{
            return Result.failed(500,"上线状态更新失败");
        }
    }

    @Override
    public Result deleteflashsaleactivity(Integer id) {
        if (mapper.deleteByPrimaryKey(id)>0){
            return Result.success("删除成功");
        }else{
            return Result.failed(500,"删除失败");
        }
    }

    @Override
    public Result modifyflashsaleactivity(FlashSaleActivity flashSaleActivity) {
        if (mapper.updateByPrimaryKeySelective(flashSaleActivity)>0){
            return Result.success("修改成功");
        }else{
            return Result.failed(500,"修改失败");
        }
    }
}
